package l2hc.gameserver.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GetIP
{
  private static final Logger _log = LoggerFactory.getLogger(GetIP.class);
  private static String IpAddress;

  private static void setIpAdd()
  {
    try
    {
      URL URL = new URL("http://www.whatismyip.org/");
      HttpURLConnection Conn = (HttpURLConnection)URL.openConnection();
      InputStream InStream = Conn.getInputStream();
      InputStreamReader Isr = new InputStreamReader(InStream);
      BufferedReader Br = new BufferedReader(Isr);

      IpAddress = Br.readLine();
    }
    catch (Exception e)
    {
      _log.info("IP service not active");
    }
  }

  public static String getIpAddress() {
    setIpAdd();
    return IpAddress;
  }
}
